//go:build wireinject
// +build wireinject

// The build tag makes sure the stub is not built in the final build.

package main

import (
	"micro-rulego/internal/biz"
	"micro-rulego/internal/conf"
	"micro-rulego/internal/server"
	"micro-rulego/internal/service"

	"github.com/go-kratos/kratos/v2"
	"github.com/go-kratos/kratos/v2/config"
	"github.com/go-kratos/kratos/v2/registry"
	"github.com/google/wire"
)

type AppWrapper struct {
	App     *kratos.App
	Debug   *DebugCollector
	Cleanup func()
}

// NewAppWrapper creates a new AppWrapper
func NewAppWrapper(app *kratos.App, debug *DebugCollector) *AppWrapper {
	return &AppWrapper{
		App:   app,
		Debug: debug,
	}
}

// initApp init kratos application.
func initApp(confSource config.Source, reg registry.Registrar) (*AppWrapper, func(), error) {
	panic(
		wire.Build(
			loadConfig,
			wire.FieldsOf(new(*conf.Bootstrap), "Logger"),
			wire.FieldsOf(new(*conf.Bootstrap), "Server"),
			wire.FieldsOf(new(*conf.Bootstrap), "Debug"),
			server.ProviderSet,
			service.ProviderSet,
			biz.ProviderSet,
			newLogger,
			newApp,
			newBroker,
			NewAppWrapper,
			NewDebugCollector,
		),
	)
}
